﻿//using System.Collections;
//using System.Collections.Generic;
//using System.Runtime.Remoting.Channels;
//using System.Runtime.Remoting.Channels.Http;
//using System.Runtime.Remoting.Channels.Tcp;
//using System.Runtime.Serialization.Formatters;
//using System.Security.Permissions;

//namespace System.Runtime.Remoting.ViewService
//{
//    [Serializable]
//    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
//    public class ViewServer : MarshalByRefObject, IViewServer
//    {
//        public static IViewServer GetViever(string Uri)
//        {
//            ChannelServices.RegisterChannel(new TcpChannel(), false);
//            return Activator.GetObject(typeof(ViewServer), Uri) as IViewServer;
//        }

//        public static void Register(ChannelType Channel, int Port, string ServiceUri)
//        {
//            var provider = new BinaryServerFormatterSinkProvider
//            {
//                TypeFilterLevel = TypeFilterLevel.Full
//            };
//            var props = new Hashtable();
//            props["port"] = Port;

//            Register(Channel == ChannelType.TCP 
//                ? (new TcpChannel(props, null, provider)) as IChannel 
//                : new HttpChannel(Port),
//                ServiceUri);
//        }

//        public static void Register(IChannel Channel, string ServiceUri)
//        {
//            ChannelServices.RegisterChannel(Channel, false);
//            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ViewServer),
//                ServiceUri, WellKnownObjectMode.Singleton);
//            RemotingConfiguration.ApplicationName = ServiceUri;
//        }

//        public static void AddAction(IRemoteAction action) { ActionsPool.Add(action); }
//        public static LamdaAction AddAction(string Name, Action action)
//        {
//            var result = new LamdaAction(Name, action);
//            ActionsPool.Add(result);
//            return result;
//        }

//        public static void AddProperty(IRemoteProperty property) { PropertiesPool.Add(property); }
//        public static RemoteProperty AddProperty(string Name, object Value)
//        {
//            var result = new RemoteProperty(Name, Value);
//            PropertiesPool.Add(result);
//            return result;
//        }

//        public static void AddEvent(IRemoteEvent Event) { EventsPool.Add(Event); }

//        public static RemoteEvent AddEvent(string Name)
//        {
//            var result = new RemoteEvent(Name);
//            EventsPool.Add(result);
//            return result;
//        }

//        public event MessageEventHandler OnMessage;

//        private void Message(string Message)
//        {
//            var handlers = OnMessage;
//            if(handlers != null)
//                handlers.Invoke(this, new MessageEventArgs { Message = Message });
//        }

//        public static void SendMessage(string Message)
//        {
//            Console.WriteLine("Message {0}", Message);
//            sf_Vievers.Foreach(v => v.Message(Message));
//        }

//        private readonly IActionsPool f_ActionsPool = new ActionsPool();
//        public IActionsPool Actions { get { return f_ActionsPool; } }

//        private readonly IPropertiesPool f_PropertyesPool = new PropertiesPool();
//        public IPropertiesPool Properties { get { return f_PropertyesPool; } }

//        private readonly IEventsPool f_EventsPool = new EventsPool();
//        public IEventsPool Events { get { return f_EventsPool; } }

//        private readonly static List<ViewServer> sf_Vievers = new List<ViewServer>();

//        public ViewServer()
//        {
//            sf_Vievers.Add(this);
//            Console.WriteLine("Viever created");
//        }

//        public void Print(string Message)
//        {
//            Console.WriteLine("Message {0}", Message);
//        }

//        public string ApplicationName { get { return AppDomain.CurrentDomain.FriendlyName; } }
//    }
//}
